package cn.edu.glut.dto;

import javax.validation.constraints.NotNull;

import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import cn.edu.glut.entity.Major;
import cn.edu.glut.entity.Student;
import cn.edu.glut.utils.ValidValue;
import lombok.Data;

@Data
public class StudentInputDTO implements DTOConvert<Student>{
	private String id;			//id
	@NotNull(message = "专业不能为空")
	private String majorId;		//专业
	@NotNull(message = ValidValue.Valid_MSG.USERNAME_NOT_NULL)
	private String username;	//学号
	@NotNull(message = ValidValue.Valid_MSG.PASSWORD_NOT_NULL)
	private String password;	//密码
	@NotNull(message = ValidValue.Valid_MSG.NAME_NOT_NULL)
	private String nickname;	//名字
	@NotNull(message = ValidValue.Valid_MSG.CLASS_NOT_NULL)
	private String sclass; // 班级
	@NotNull(message = ValidValue.Valid_MSG.CONTACT_NOT_NULL)
	private String contact; // 联系方式（电话号码）
	
	@Override
	public Student convertToEntity() {
		Student s = new Student();
		BeanUtils.copyProperties(this, s);
		if(!StringUtils.isEmpty(majorId)){
			Major m = new Major(majorId);
			s.setMajor(m);
		}
		return s;
	}
	
	
}
